In [1]:
Pdmin = 0.9
Pfa = 0.1
Att = 71.53 - 40
In [2]:
import glob
import re
def get_ccdf(x):
xs = array(x)
xs.sort()
N = float(len(xs))
P = arange(N)/N
return xs, P
def get_gamma0(gammaN):
gammaN, Pd = get_ccdf(gammaN)
gamma0 = interp(1. - Pfa, Pd, gammaN)
return gamma0
def iterate_campaign(path):
for fn in glob.glob(path):
g = re.search("_m([0-9_]+)dbm\.dat$", fn)
if g:
Pg = -float(g.group(1).replace('_', '.'))
gamma = loadtxt(fn)
yield Pg, gamma
def get_campaign_g(path, gamma0):
Pg = []
Pd = []
for Pg0, gamma in iterate_campaign(path):
Pg.append(Pg0)
Pd.append(mean(gamma > gamma0))
Pg = array(Pg)
Pd = array(Pd)
Pga = Pg.argsort()
Pd = Pd[Pga]
Pg = Pg[Pga]
return Pg, Pd
def get_campaign(path, gamma0):
Pg, Pd = get_campaign_g(path, gamma0)
Pin = Pg - Att
return Pin, Pd
def get_Pinmin(path, Pdth=Pdmin):
gamma0 = None
for fn in glob.glob(path):
if fn.endswith("_off.dat"):
gammaN = loadtxt(fn)
gamma0 = get_gamma0(gammaN)
break
Pin, Pd = get_campaign(path, gamma0)
Pinmin = interp(Pdth, Pd, Pin)
return Pinmin
def get_method_ps(glob_path):
method_ps = set()
for path in glob.glob(glob_path):
g = re.search("ks_(.*)_m", path)
if g:
method_ps.add(g.group(1))
return sorted(method_ps)
def get_batch_Pinmin_permethod(path, Pdth=Pdmin):
method_ps = get_method_ps(path)
Pinmin_permethod = {}
for method_p in method_ps:
path2 = path.replace("*", "%s_*" % (method_p,))
Pinmin_permethod[method_p] = get_Pinmin(path2, Pdmin)
return Pinmin_permethod
Pinmin_permethod = get_batch_Pinmin_permethod("../measurements/pd/usrp/sim_usrp_micsoft_fs2mhz_Ns25ks_*.dat")
In [3]:
Pinmin_permethod
Out[3]:
In [4]:
def get_benchmark_data():
Ns = 25000
time_permethod = {}
for line in open("../measurements/benchmark/benchmark-ninestein.dat"):
g = re.match("(.*\))\s+(\d+)\s+([0-9.]+)", line)
if not g:
print "corrupted:", line
continue
method = g.group(1)
Ns0 = int(g.group(2))
time0 = float(g.group(3))
slug = method.lower()
slug = re.sub(r"detector\(l=(\d+)\)", r"_l\1", slug)
slug = re.sub(r"scfdetector\(np=(\d+), l=\d+\)", r"scf_Np\1", slug)
slug = re.sub(r"energydetector\(\)", "ed", slug)
if Ns0 == Ns:
time_permethod[slug] = time0
return time_permethod
time_permethod = get_benchmark_data()
In [5]:
time_permethod
Out[5]:
In [6]:
#method = []
#methodtime = []
#methodPinmin = []
#mclass = []
from collections import defaultdict
methodtime = defaultdict(list)
methodPinmin = defaultdict(list)
for m in Pinmin_permethod.keys():
Pinmin = Pinmin_permethod[m]
if m not in time_permethod:
#continue
m2 = re.sub("^c(..._l)", r"\1", m)
else:
m2 = m
t = time_permethod[m2]/time_permethod['ed']
if 'ed' in m:
c = 'ed'
elif 'scf' in m:
c = 'scf'
elif re.match("c..._l", m):
if 'cav' in m or 'cfn' in m or 'mac' in m:
c = 'ccbd'
else:
c = 'cebd'
elif 'cav' in m or 'cfn' in m or 'mac' in m:
c = 'cbd'
else:
c = 'ebd'
methodtime[c].append(t)
methodPinmin[c].append(Pinmin)
#mclass.append(c)
#method.append(m)
#methodtime.append(t)
#methodPinmin.append(Pinmin)
In [7]:
#scatter(methodtime, methodPinmin, s=100, c=mclass)
#figure(figsize=(10, 8))
ms=10
mfc=(.8,.8,.8)
mew=1
plot(methodtime['ed'], methodPinmin['ed'], 'o', label='energy', ms=ms, mfc=mfc, mew=mew)
plot(methodtime['cbd'], methodPinmin['cbd'], '^', label='covariance', ms=ms, mfc=mfc, mew=mew, zorder=3)
plot(methodtime['ebd'], methodPinmin['ebd'], '^', label='eigenvalue', ms=ms, mfc='w', mew=mew)
#plot(methodtime['ccbd'], methodPinmin['ccbd'], 'v', label='covariance\n(with noise comp.)', ms=ms*.5, mfc='k', mew=mew, mec='k')
#plot(methodtime['cebd'], methodPinmin['cebd'], 'v', label='cov. eigenvalue\n(with noise comp.)', ms=ms*.5, mfc='w', mew=mew, mec='k')
plot(methodtime['scf'], methodPinmin['scf'], 's', label='cyclostationary', ms=ms, mfc=mfc, mew=mew)
xlabel("$t_{CPU}$ [relative to energy detection]")
ylabel("$P_{in}$ [dBm] @ $P_d = 0.9$")
xscale('log')
axis([.4, 1e5, -120, -100])
legend(ncol=1)
title("USRP @ $f_s=2$MHz, $N_s=25$ksamples")
grid()
savefig("time_pin_min_comparison.eps")
In [7]:
In [7]: